#ifndef STRING_UTILITIES_H
#define	STRING_UTILITIES_H

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <iterator>

/**
 * Trim the right side of a string using a delimiter.
 * The delimiter contains all the characters which will be trimmed
 * on the rightside of the string.
 * @param s is the string that needs trimming
 * @param t is the string that contains all the characters that can be
 * used for trimming. Default value is a space.
 * @return The trimmed string
 */
std::string trim_right(const std::string & s,
	const std::string & t = " ");
/**
 * Trim the left side of a string using a delimiter.
 * The delimiter contains all the characters which will be trimmed
 * on the leftside of the string.
 * @param s is the string that needs trimming
 * @param t is the string that contains all the characters that can be
 * used for trimming. Default value is a space.
 * @return The trimmed string
 */
std::string trim_left(const std::string & s, const std::string & t = " ");
/**
 * Trim the left & right side of a string using a delimiter.
 * The delimiter contains all the characters which will be trimmed
 * on the left & rightside of the string.
 * @param s is the string that needs trimming
 * @param t is the string that contains all the characters that can be
 * used for trimming. Default value is specified by the variable delim.
 * @return The trimmed string
 */
std::string trim(const std::string & s, const std::string & t = " ");
/**
 * Split a string into a vector of tokens using a delimiter.
 * If empty entries are detected, they can be removed if specified.
 * @param s is the string that needs trimming
 * @param tokens is a vector of string tokens and
 * stores the result of the split
 * @param delim is the string that contains all the characters that can be
 * used for splitting. Default value is a space.
 * @param remove_empty if true empty entries are not stored in the
 * vector of tokens, if false empty entries are stored in the
 * vector of tokens. Default value is true.
 * @return Number of the tokens parsed
 */
unsigned long split(const std::string& s, std::vector<std::string>& tokens,
	const std::string& delim, bool remove_empty = true);

/**
 * Convert a string into a double.
 * If an input / output error is detected, zero will be returned.
 * @param s is the string that will be converted into a double
 * @return Double is returned if no error occurs, otherwise 0 is returned
 */
double str2double(const std::string& s);
/**
 * Convert a string into a integer.
 * If an input / output error is detected, zero will be returned.
 * @param s is the string that will be converted into a integer
 * @return Integer is returned if no error occurs, otherwise 0 is returned
 */
int str2int(const std::string& s);
/**
 * Evaluates if a string starts with a specified string. If the string
 * starts with the specified string, true is returned,
 * if not false is returned.
 * @param s is that string that will be evaluated
 * @param t is the string that will be used to evaluate the string
 * @return True if the string was found in the beginning of string s, false
 * if not
 */
bool startsWith(const std::string& s, const std::string& t);
/**
 * Convert a double into a string
 * @param d is the double that will be converted into a string
 * @return String representation of the double
 */
std::string double2str(const double d);
/**
 * Convert an integer into a string
 * @param x is the integer that will be converted into a string
 * @return String representation of the integer
 */
std::string int2str(const int x);
/**
 * Convert a long into a string
 * @param x is the long that will be converted into a string
 * @return String representation of the long
 */
std::string long2str(const long x);
/**
 * Check if a character is a number between 0 and 9
 * @param c is a char for which the function checks if it is a number
 * between 0 and 9.
 * @return True if the character is a number, false if not
 */
bool isDigit(const char c);
/**
 * Check if a string is an integer. The string may end with:
 *
 * - \n
 * - \r
 *
 * @param s is a string that will be checked if it 's an integer
 * @return True if the string is an integer, false if not.
 */
bool isInteger(const std::string& s);
/**
 * Check if a string is a double. The string may end with:
 *
 * - \n
 * - \r
 *
 * @param s is a string that will be checked if it 's a double
 * @return True if the string is a double, false if not.
 */
bool isDouble(const std::string& s);

#endif	/* STRING_UTILITIES_H */

